package com.androidRtc.controller;

import com.alibaba.fastjson.JSONObject;
import com.androidRtc.dao.UserDao;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class FindDataServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        JSONObject json = new JSONObject();
        String username;
        UserDao dao = new UserDao();
        PrintWriter out;
        username = request.getParameter("username");
        //1.【调用DAD】将查询命令推送到数据库服务器上，得到所有用户信息【list】
        json = dao.findData(username);
        //2.【调用响应对象】将用户信息结合<table>标签命令以二进制形式写入到响应体中
        response.setContentType("text/html;charset=utf-8");
        out = response.getWriter();
        out.print(json.toString());
    }
}
